
<h1><span class="yiyi-st" id="yiyi-12">numpy.extract</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.extract.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.extract.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.extract"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">extract</code><span class="sig-paren">(</span><em>condition</em>, <em>arr</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/lib/function_base.py#L1912-L1960"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">返回满足某些条件的数组的元素。</span></p>
<p><span class="yiyi-st" id="yiyi-15">这相当于<code class="docutils literal"><span class="pre">np.compress（ravel（condition），</span> <span class="pre">ravel（arr））</span></code>。</span><span class="yiyi-st" id="yiyi-16">如果<em class="xref py py-obj">条件</em>是布尔<code class="docutils literal"><span class="pre">np.extract</span></code>等效于<code class="docutils literal"><span class="pre">arr[condition]</span></code>。</span></p>
<p><span class="yiyi-st" id="yiyi-17">请注意，<a class="reference internal" href="numpy.place.html#numpy.place" title="numpy.place"><code class="xref py py-obj docutils literal"><span class="pre">place</span></code></a>与<a class="reference internal" href="#numpy.extract" title="numpy.extract"><code class="xref py py-obj docutils literal"><span class="pre">extract</span></code></a>完全相反。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-18">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-19"><strong>condition</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-20">数组，其非零或True条目表示要提取的<em class="xref py py-obj">arr</em>的元素。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>arr</strong>：array_like</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">输入与<em class="xref py py-obj">条件</em>相同大小的数组。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-23">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-24"><strong>提取</strong>：ndarray</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-25">来自<em class="xref py py-obj">arr</em>的值1的数值组，其中<em class="xref py py-obj">条件</em>为真。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-26">也可以看看</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-27"><a class="reference internal" href="numpy.take.html#numpy.take" title="numpy.take"><code class="xref py py-obj docutils literal"><span class="pre">take</span></code></a>, <a class="reference internal" href="numpy.put.html#numpy.put" title="numpy.put"><code class="xref py py-obj docutils literal"><span class="pre">put</span></code></a>, <a class="reference internal" href="numpy.copyto.html#numpy.copyto" title="numpy.copyto"><code class="xref py py-obj docutils literal"><span class="pre">copyto</span></code></a>, <a class="reference internal" href="numpy.compress.html#numpy.compress" title="numpy.compress"><code class="xref py py-obj docutils literal"><span class="pre">compress</span></code></a>, <a class="reference internal" href="numpy.place.html#numpy.place" title="numpy.place"><code class="xref py py-obj docutils literal"><span class="pre">place</span></code></a></span></p>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-28">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">arr</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">arange</span><span class="p">(</span><span class="mi">12</span><span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">((</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">arr</span>
<span class="go">array([[ 0,  1,  2,  3],</span>
<span class="go">       [ 4,  5,  6,  7],</span>
<span class="go">       [ 8,  9, 10, 11]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">condition</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">mod</span><span class="p">(</span><span class="n">arr</span><span class="p">,</span> <span class="mi">3</span><span class="p">)</span><span class="o">==</span><span class="mi">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">condition</span>
<span class="go">array([[ True, False, False,  True],</span>
<span class="go">       [False, False,  True, False],</span>
<span class="go">       [False,  True, False, False]], dtype=bool)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">extract</span><span class="p">(</span><span class="n">condition</span><span class="p">,</span> <span class="n">arr</span><span class="p">)</span>
<span class="go">array([0, 3, 6, 9])</span>
</pre></div>
</div>
<p><span class="yiyi-st" id="yiyi-29">如果<em class="xref py py-obj">条件</em>是布尔值：</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">arr</span><span class="p">[</span><span class="n">condition</span><span class="p">]</span>
<span class="go">array([0, 3, 6, 9])</span>
</pre></div>
</div>
</dd></dl>
